package com.java.zhuiyun.api.course_unit.mapper;

import com.java.zhuiyun.api.course_unit.entity.CourseUnit;
import com.java.zhuiyun.api.file_manager.entity.FileManager;
import com.java.zhuiyun.common.mapper.BaseMapper;
import com.java.zhuiyun.common.response.CommonResult;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @ClassName CourseUnitMapper
 * @Description TODO
 * @Author 杨友朋
 * @Date 2023/8/15 19:52
 **/
@Mapper
public interface CourseUnitMapper extends BaseMapper<CourseUnit> {

    /**
     * @Author 杨友朋
     * @Description TODO 查询章节
     * @Date 2023/8/15 20:56
     * @Return
     * @param
     */
    @Select("select * from course_unit where course_id=#{courseId} and del_flag=0")
    List<CourseUnit> selectUnit(Integer courseId);

    /**
    * @Author MJL
    * @Description todo 章节内上传视频
    * @Date 2023/8/17 10:20
    * @Return  * @param null
    */
    @Update("update course_unit set file_id = #{fileId} where id = #{id}")
    Integer addFile(CourseUnit courseUnit);

    /**
    * @Author MJL
    * @Description todo 查询可以上传的视频
    * @Date 2023/8/17 14:29
    * @Return  * @param null
    */
    @Select("select file_manager_id,file_manager_name from file_manager " +
            "where file_type = '.mp4' and audit_type = 1 and del_flag = 0 " +
            "ORDER BY create_time DESC")
    List<FileManager> selectFile(String fileType);

    /**
    * @Author 杨友朋
    * @Description TODO 修改章节
    * @Date 2023/8/21 16:05
    * @Return
    * @param
    */
    @Update("update course_unit set unit_title=#{unitTitle},unit_info=#{unitInfo} where id=#{id}")
    Integer updateUnit(CourseUnit courseUnit);

    /**
    * @Author 杨友朋
    * @Description TODO 删除章节
    * @Date 2023/8/21 16:46
    * @Return
    * @param
    */
    @Update("update course_unit set del_flag=1 where id=#{id}")
    Integer delUnit(Integer id);

    /**
     * @Author 杨友朋
     * @Description TODO 单查章节
     * @Date 2023/8/24 9:00
     * @Return
     * @param
     */
    @Select("select * from course_unit where id=#{id} and del_flag=0")
    CourseUnit selectUnitById(Integer id);

    /**
     * @Author 杨友朋
     * @Description TODO 更改状态
     * @Date 2023/8/24 9:23
     * @Return
     * @param
     */
    @Update("update course_unit set unit_status=#{unitStatus},update_time=#{updateTime} where id=#{id}")
    Integer updateSwitch(CourseUnit courseUnit);

    /**
    * @Author MJL
    * @Description todo 将章节进行下架操作
    * @Date 2023/9/2 21:18
    * @Return  * @param null
    */
    @Update("update course_unit set unit_status = 1 where id = #{id}")
    Integer banned(Integer id);

    /**
    * @Author MJL
    * @Description todo 将章节进行上架操作
    * @Date 2023/9/2 21:30
    * @Return  * @param null
    */
    @Update("update course_unit set unit_status = 0 where id = #{id}")
    Integer enables(Integer id);
}
